package com.hnevc.restaurant.controller;



import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hnevc.restaurant.entity.User;
import com.hnevc.restaurant.service.UserService;



@Controller
@RequestMapping("/user")
public class UserController {
	
	public static final String K_USERID = "kUSERID";
	public static final String SESSION_AUTHS = "kAUTHS";
	
	
	@Resource
	UserService userService;
	
	@RequestMapping(value="/login")
	public String login() {
		return "login";
	}
	@RequestMapping(value="/doLogin", method=RequestMethod.POST)
	@ResponseBody
	public User doLogin(HttpSession session,@RequestBody User user) {
		User u = userService.login(user);
		if(u!=null){
			session.setAttribute(K_USERID, user.getUserName());
		}
		return u;
	}
	/*
	 * 使用x-www-form-urlencoded数据格式方式提交
	 * */
	@RequestMapping(value="/doLogin2", method=RequestMethod.POST)
	@ResponseBody
	public User doLogin2(User user) {
		User u = userService.login(user);
		return u;
	}
	/*
	 * 使用Get方式提交
	 * */
	@RequestMapping(value="/doLogin3", method=RequestMethod.GET)
	@ResponseBody
	public User doLogin3(User user) {
		User u = userService.login(user);
		return u;
	}
	
}
